package com.supermarket.api.web;

import com.supermarket.api.bean.shop.ShopProductReq;
import com.supermarket.api.common.BaseResponse;
import com.supermarket.api.common.PageParam;
import com.supermarket.api.entity.ProductEntity;
import com.supermarket.api.entity.ShopEntity;
import com.supermarket.api.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 店铺接口
 * @author 李其伟
 * @date 2023/10/16
 */
@Controller
@RequestMapping("/shop")
public class ShopController {

    /**
     * 推荐品牌
     */
    @Autowired
    private ShopService shopService;

    @ResponseBody
    @GetMapping("/list")
    public String list(PageParam pageParam){
        Page<ShopEntity> page = shopService.list(pageParam);
        return BaseResponse.successJson(page);
    }

    @ResponseBody
    @GetMapping("/detail/{shopId}")
    public String detail(@PathVariable Long shopId){
        ShopEntity res = shopService.detail(shopId);
        return BaseResponse.successJson(res);
    }

    @ResponseBody
    @GetMapping("/productList")
    public String productList(ShopProductReq req){
        Page<ProductEntity> page = shopService.productList(req);
        return BaseResponse.successJson(page);
    }
}
